﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace CATLTempUpdate
{
    public partial class FmTestSocket : Form
    {
        Socket socket;
        public FmTestSocket()
        {
            InitializeComponent();
        }

        private void FmTestSocket_Load(object sender, EventArgs e)
        {

        }

        private void btnconnect_Click(object sender, EventArgs e)
        {
            string ip = tbxip.Text;
            int  port = Convert.ToInt32(tbxport.Text);
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //连接到指定服务器的指定端口
            try
            {
                socket.Connect(ip, port);


                Console.WriteLine("connect to the server");
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接服务器失败！");
            }
            
           // Console.Read();


        }

        private void btnoffline_Click(object sender, EventArgs e)
        {
            //socket.Disconnect(true);
            try
            {
                socket.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("断开服务器失败！");
            }
            
        }
    }
}
